﻿/*****************************************************
**Copyright(C), 2021-2022, Ciqtek Technology.
**Version:     dev
**Author:      MiPeng
**Date:        2022/04/18
**Description: 图标旋转动画
*****************************************************/

#ifndef ROTATIONLABEL_H
#define ROTATIONLABEL_H

#include "../generalui_global.h"
#include "../GlobalUIDef.h"

#include <QLabel>
#include <QTimer>

namespace GeneralUI {

	class GENERALUI_EXPORT RotationLabel : public QLabel
	{
		Q_OBJECT

	public:
		explicit RotationLabel(QWidget *parent = nullptr);
		~RotationLabel();

	public:
		/**
		 * @brief  setIcon  设置图标
		 * @param  pixMap
		 * @return void
		 */
		void setIcon(QPixmap &pixMap);

		/**
		 * @brief  setAngle  设置单次旋转角度
		 * @param  angle  单次旋转角度
		 * @return void
		 */
		void setAngle(double angle);

		/**
		 * @brief  start  开始旋转
		 * @param  interval  旋转间隔
		 * @return void
		 */
		void start(int interval = 150);

		/**
		 * @brief  stop  停止旋转
		 * @return void
		 */
		void stop();

	private Q_SLOTS:
		/**
		 * @brief  slotIconRotate  进行旋转
		 * @return void
		 */
		void slotIconRotate();

	protected:
		/**
		 * @brief  hideEvent  隐藏事件
		 * @param  event
		 * @return void
		 */
		void hideEvent(QHideEvent *event);

		/**
		 * @brief  paintEvent  绘制事件
		 * @param  event
		 * @return void
		 */
		void paintEvent(QPaintEvent *event);

	private:
		QTimer *m_timer;					/// 图标旋转定时器
		double m_angle;						/// 单次旋转角度
		double m_rotateAngle;				/// 当前旋转角度
		QPixmap m_icon;						/// 图标
		int m_rotateIndex;					/// 旋转次数
	};

}//namespace OfUI 

#endif // ROTATIONLABEL_H
